<template>
	<view class="body">
		
		<view class="xsbox" v-for="(item,index) in lists">
			
			<view class="xslist_out">
				
				<view class="xslistx">
					<view class="xslistx1">用户信息</view>
					<view class="xslistx2">{{item.name}} {{item.mobile}}</view>
				</view>
				<view class="xslistx">
					<view class="xslistx1">产品</view>
					<view class="xslistx2">{{item.remark}}</view>
				</view>
				
				<view class="xslistx">
					<view class="xslistx1">数量/价格</view>
					<view class="xslistx2">{{item.number}} / {{item.money}}</view>
				</view>
				
				<view class="xslistx">
					<view class="xslistx1">地址</view>
					<view class="xslistx2">{{item.address}}</view>
				</view>
				
				<view class="xslistx">
					<view class="xslistx1">来源</view>
					<view class="xslistx2">{{item.from}}</view>
				</view>
				<view class="xslistx">
					<view class="xslistx1">时间</view>
					<view class="xslistx2">用户信息</view>
				</view>

		
			</view>
			
			<view style="height: 10rpx;"></view>
			
			<view class="xsbootom">
				<view class="xsbootom1">
					<text v-if="item.select==0" @tap="selectme1" :data-i="index" class="icon-xuanzekuangmoren iconfont"></text>
					<text v-if="item.select==1" @tap="selectme0" :data-i="index" style="color: #08b059;" class="icon-wancheng iconfont"></text>
				</view>
				<view class="xsbootom2" @tap="deletexs" :data-id="item.id" > <text class="icon-shanchu1 iconfont"></text> </view>
			</view>
			
		</view>
		
		<view style="height: 130rpx;"></view>
		
		<view class="bottom">
			
			<view class="bottoms" @tap="fenpeixs">
				分配
			</view>
		</view>
		
		
		<view class="windos" v-if="show==1">
			
			<view class="windos_in">
				
				<view style="height: 100rpx;"></view>
				
				<view class="windos_ins">
					<view class="windos_ins1">分配方式</view>
					<view class="windos_ins2">
						<picker @change="gettypes"  :range="types">
							{{types_t==''?'请选择':types_t}}
						</picker>
						
					</view>
				</view>
				
				<view class="windos_ins">
					<view class="windos_ins1">分配对象</view>
					<view class="windos_ins2">
						<picker @change="getuserid" :value="index" range-key="nickname" :range="getlist">
							<view class="uni-input">{{uname==''?'请选择':uname}}</view>
						</picker>
					</view>
					
				</view>
				
				<view class="windosbtn">
					
					<view class="windosbtn1" @tap="showhide" > 取消 </view>
					<view class="windosbtn2" @tap="submits"> 分配 </view>
				</view>
				
			</view>
			
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lists:[],
				show:0,
				types:['部门','个人'],
				types_t:'',
				getlist:[],
				all:[],
				alluser:[],
				uname:'',
				uid:''
			}
		},
		onShow() {
			this.getallxs();
			this.getuser();
		},
		
		methods: {
			
			submits(){
				var that=this;
				var types_t=this.types_t;
				var uid=this.uid;
				
				var lists=this.lists;
				var str='';
				lists.forEach(function(item){
					
					if (item.select==1) {
						str+=item.id + ','
					}	
					
				})
				
				console.log(str,types_t,uid);
				
				that.$u.api.getProductLists11({ids:str,'types_t':types_t,'uid':uid}).then(res => {
					
					uni.showToast({
						icon:'none',
						title:res.msg
					})
					
					if (res.code==1) {
						that.show=0;
						that.getallxs();
					}	
					
			
				})
				
			},
			
			getuserid(ret){
				console.log(ret)
				var i=ret.detail.value
				var list=this.getlist;
				var uname=list[i].nickname
				var uid=list[i].id
				this.uname=uname;
				this.uid=uid;
			},
			
			
			gettypes(ret){
				console.log(ret)
				var i=ret.detail.value
				var list=this.types;
				var that=this;
				console.log(list[i])
				
				that.types_t=list[i];
				that.uname='';
				that.uid='';
				
				if (i==0) {
					that.getlist=this.all
				} else{
					that.getlist=this.alluser
				}	
				
			},
			
			fenpeixs(){
				this.show=1;
			},
			
			showhide(){
				this.show=0;
			},
			
			deletexs(s){
				var that=this;
				var id=s.currentTarget.dataset.id;
				
				uni.showModal({
					title:'温馨提示',
					content:'确定要删除?',
					success(ret) {
						console.log(ret)
						if (ret.confirm) {
							that.$u.api.getProductLists9({id:id}).then(res => {
								console.log(res)
								that.getallxs();
							})
						}	
					}
				})
			},
			selectme1(s){
				console.log(s);
				var i=s.currentTarget.dataset.i;
				var lists=this.lists;
				lists[i].select=1;
				this.lists=lists;
			},
			
			selectme0(s){
				var i=s.currentTarget.dataset.i;
				var lists=this.lists;
				lists[i].select=0;
				this.lists=lists;
			},
			
			getallxs(){
				var that=this;
				
				that.$u.api.getProductLists8({}).then(res => {
					console.log(res)
					that.lists=res.data
				})
				
			},
			getuser(){
				var that=this;
				
				that.$u.api.getProductLists10({}).then(res => {
					console.log(res)
					that.alluser=res.data.alluser
					that.all=res.data.all
					that.getlist=res.data.alluser
				})
				
			}
		}
	}
</script>

<style>
	.windosbtn2{
		width: 180rpx;height: 60rpx;
		background: #08b059;color: #ffffff;
		text-align: center;line-height: 50rpx;
		border-radius: 60rpx;
	}
	.windosbtn1{
		width: 180rpx;height: 60rpx;
		text-align: center;line-height: 50rpx;
		border-radius: 60rpx;border: 1px solid #ececec;
	}
	
	.windosbtn{
		width: 450rpx;height: 200rpx;margin: auto;
		display: flex;align-items: center;
		justify-content: space-between;
	}
	
	.windos_ins2{
		width: 400rpx;
		line-height: 70rpx;
		font-size: 30rpx;font-weight: 500;
	}
	.windos_ins1{
		width: 200rpx;
		font-size: 30rpx;font-weight: 500;
		line-height: 70rpx;
	}
	.windos_ins{
		width: 650rpx;height: 70rpx;margin: auto;
		display: flex;align-items: center;
	}
	.windos_in{
		width: 710rpx;height: 500rpx;background: #ffffff;
		border-radius: 10rpx;position: absolute;
		top: 0;bottom: 0;left: 0;right: 0;margin: auto;
	}
	.windos{
		width: 750rpx;min-height: 100vh;
		position: fixed;top: 0px;z-index: 999;
		background: rgba(1, 1, 1, 0.375);
	}
	
	.bottoms{
		width: 710rpx;height: 80rpx;border-radius: 80rpx;
		margin: auto;
		background: #08b059;color: #ffffff;font-weight: 500;
		font-size: 32rpx;
		text-align: center;line-height: 80rpx;
	}
	
	.bottom{
		width: 750rpx;height: 100rpx;position: fixed;
		bottom: 0px;background: #ffffff;
	}
	
	.xsbootom{
		width: 670rpx;height: 90rpx;margin: auto;
		border-top: 1px solid #ececec;
		display: flex;align-items: center;justify-content: space-between;
	}
	
	.xslistx2{
		font-size: 28rpx;font-weight: 500;color: #555555;
	}
	.xslistx1{
		font-size: 28rpx;font-weight: 500;color: #333333;
	}
	.xslistx{
		width: 680rpx;height: 50rpx;
		display: flex;align-items: center;justify-content: space-between;
	}
	.xslist_out{
		width: 680rpx;height: auto;margin: auto;
	}
	.xsbox{
		width: 710rpx;height: auto;margin: auto;
		margin-top: 20rpx;border-radius: 10rpx;
		box-shadow:0px 0px 8px 0px rgba(50, 50, 50, 0.275);
	}
	.body{
		width: 100%;min-height: 100vh;background: #fbfbfb;
	}
	
	
</style>
